package com.ylfstu.debug_;

public class DynamicBinding {
    public static void main(String[] args) {
        A a = new B();
        System.out.println(a.sum());//正常情况输出40  30
        System.out.println(a.sum1());//正常输出30  20

    }
}

class A {
    public int i = 10;
    public int getI() {
        return i;
    }
    public int sum() {
        return getI() + 10;
    }
    public int sum1() {
        return i + 10;
    }
}
//B类作为A类的继承
class B extends A {
    public int i = 20;

    @Override
    public int getI() {
        return i;
    }

//    @Override
//    public int sum() {
//        return i + 20;
//    }
//
//    @Override
//    public int sum1() {
//        return i + 10;
//    }

    public void say() {
        System.out.println("This is B 对象");
    }
}
